package controller;

import hibernate.HibernateSessionFactory;
import hibernate.Orderstab;
import hibernate.OrderstabDAO;
import android.webSocketEndPoint;
import com.opensymphony.xwork2.Action;


public class OrderAcceptAction implements Action {
	private String check;
	private Orderstab orderstab;
	private int orderId;
	private int parkId;
	private int driverId;
	

	public String getCheck() {
		return check;
	}


	public void setCheck(String check) {
		this.check = check;
	}


	@Override
	public String execute() throws Exception {
		String checks[] = this.getCheck().split(", ");
		for(String c :checks){
			//将订单号为c的订单状态置为1，然后调用接口通知安卓
			HibernateSessionFactory.getSession().beginTransaction();
			OrderstabDAO orderstabDAO = new OrderstabDAO();
			try{
				orderstab = orderstabDAO.findById(Integer.parseInt(c));
				orderId = Integer.parseInt(c);
				parkId = orderstab.getParkstab().getUuid();
				driverId = orderstab.getDriverstab().getUuid();
				orderstab.setState(1);
				orderstabDAO.getSession().update(orderstab);
				orderstabDAO.getSession().getTransaction().commit();
			}
			catch(Exception e){
				e.printStackTrace();
			}
			finally{
				orderstabDAO.getSession().close();
			}
			webSocketEndPoint.onOrderAccept(driverId,parkId,orderId);
		}
		return SUCCESS;
	}

}
